package com.example.zyfypt_206shj.model;


import com.example.zyfypt_206shj.bean.ArticleBean;
import com.example.zyfypt_206shj.bean.CollectionBean;
import com.example.zyfypt_206shj.bean.TwareBean;
import com.example.zyfypt_206shj.iface.CollectionListener;
import com.example.zyfypt_206shj.iface.Collectioniface;
import com.example.zyfypt_206shj.service.CollectionService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Raindy on 2017/4/22.
 */

public class CollectionModel_tware implements Collectioniface<TwareBean> {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";

    //构造方法
    public CollectionModel_tware()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }


    @Override
    public void getResultList(String mod, int page, String sessionID, final CollectionListener<TwareBean> listener) {
        CollectionService collectionService = retrofit.create(CollectionService.class);
        Call<List<CollectionBean<TwareBean>>> call = collectionService.getCTwareList(mod,page,sessionID);
        call.enqueue(new Callback<List<CollectionBean<TwareBean>>>() {
            @Override
            public void onResponse(Call<List<CollectionBean<TwareBean>>> call, Response<List<CollectionBean<TwareBean>>> response) {
                if (response.isSuccessful() && response.body()!=null)
                    listener.onResponse(response.body());
                else
                    listener.onFail("on response fall");
            }

            @Override
            public void onFailure(Call<List<CollectionBean<TwareBean>>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
